package com.xm.xmwa1706090.service.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xm.xm.dto.RequestDto;
import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xm.util.*;
import com.xm.xmwa1706090.service.dto.*;
import com.xm.xmwa1706090.service.mapper.*;
import com.xm.xmwa1706090.service.model.*;
import com.xm.xmwa1706090.service.service.QbUcenterMemberService;
import com.xm.xmwa1706090.service.service.TokenManager;
import com.xm.xmwa1706090.service.util.DateUtil;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;

/**
 * 杭州新苗网络科技有限公司
 * @author meihf
 * @date 2017/07/07
 * @description
*/
@Service("qbUcenterMemberService")
public class QbUcenterMemberServiceImpl extends ServiceImpl<QbUcenterMemberMapper,QbUcenterMember> implements QbUcenterMemberService {

    protected static final Logger logger = Logger.getLogger("ServiceImpl");

    @Autowired
    QbSmsMapper qbSmsMapper;

    @Autowired @Qualifier("redisTemplate")
    public RedisTemplate<String,Integer> redisTemplate;

    @Autowired
    QbUcenterMemberMapper qbUcenterMemberMapper;

    @Autowired
    QbMemberMapper qbMemberMapper;

    @Autowired
    QbRidingDetailMapper qbRidingDetailMapper;

    @Autowired
    QbAuthGroupAccessMapper qbAuthGroupAccessMapper;

    @Autowired
    QbInvoiceMapper qbInvoiceMapper;

    @Autowired
    QbAboutMeMapper qbAboutMeMapper;

    @Autowired
    QbFeedbackMapper qbFeedbackMapper;

    @Autowired
    QbKefuTelMapper qbKefuTelMapper;

    @Autowired
    QbLimitMoneyMapper qbLimitMoneyMapper;

    @Autowired
    QbMoneyDetailMapper qbMoneyDetailMapper;

    @Autowired
    QbCouponMapper qbCouponMapper;

    @Autowired
    TokenManager tokenManager;

    @Override
    public ResultDto login(SearchDto searchDto) {
        //填写验证码以及手机号进行登录
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
             if (!filed.has("mobile") || !filed.has("validateCode")){
                  resultDto.setMsg(ErrorCode.E10011);
                  resultDto.setCode(ErrorCode.C10011);
                  return resultDto;
              }else{
                  String mobile = filed.getString("mobile");
//                  ResultDto smsResult = checkSMS(searchDto);
//                 if (smsResult.getCode() != 0) {
//                     return smsResult;
//                 }
                 //验证通过后将数据插入到数据库中
                 //如果库中之前存在就直接过去
                 QbUcenterMember qbUcenterMember = new QbUcenterMember();
                 qbUcenterMember.setMobile(mobile);
                 qbUcenterMember.setUsername(mobile);
                 QbUcenterMember member = qbUcenterMemberMapper.selectOne(qbUcenterMember);

                 QbUcenterMemberDto ucenterMemberDto = new QbUcenterMemberDto();
                 if (member!=null){
                     TokenModel tokenModel = tokenManager.createToken(member.getId(), String.valueOf(UUID.randomUUID()),member.getMobile());
                     ucenterMemberDto = BeanUtils.copy(member,QbUcenterMemberDto.class);
                     ucenterMemberDto.setToken(tokenModel.getToken());
                 }else {
                     qbUcenterMember.setPassword(DigestUtils.md5Hex("123456"));
                     qbUcenterMember.setReg_time(searchDto.getTime().intValue());
                     qbUcenterMember.setReg_ip(filed.getString("ip"));
                     qbUcenterMember.setStatus(1);
                     qbUcenterMemberMapper.insert(qbUcenterMember);
                     QbUcenterMember insertMember = qbUcenterMemberMapper.selectOne(qbUcenterMember);
                     //保存到权限表
                     QbAuthGroupAccess qbAuthGroupAccess = new QbAuthGroupAccess();
                     qbAuthGroupAccess.setUid(insertMember.getId());
                     qbAuthGroupAccess.setGroup_id(2);
                     qbAuthGroupAccessMapper.insert(qbAuthGroupAccess);
                     //保存到用户信息表
                     QbMember qbMember = new QbMember();
                     qbMember.setAccount((double) 0);
                     qbMemberMapper.insert(qbMember);
                     TokenModel tokenModel = tokenManager.createToken(insertMember.getId(), String.valueOf(UUID.randomUUID()),insertMember.getMobile());
                     ucenterMemberDto = BeanUtils.copy(insertMember,QbUcenterMemberDto.class);
                     ucenterMemberDto.setToken(tokenModel.getToken());
                 }
                 //登录成功生成token
                 resultDto.setData(ucenterMemberDto);
              }
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto updateUserInfo(RequestDto requestDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = requestDto.getFiled();
        try {
            //1：男 2：女  3：保密
             if (!filed.has("face") || !filed.has("birthday")
                     || !filed.has("sex") || !filed.has("nickname")){
                  resultDto.setMsg(ErrorCode.E10011);
                  resultDto.setCode(ErrorCode.C10011);
                  return resultDto;
              }else{
                  String face = filed.getString("face");
                  String birthday = filed.getString("birthday");
                  int sex = filed.getInt("sex");
                  String nickname = filed.getString("nickname");
                  int birthday_date = DateUtils.getStringToInt_seconds(birthday,DateUtil.PATTERN_DATE_TIME);
                  QbMember qbMember = new QbMember();
                  qbMember.setUid(requestDto.getAppUserId().intValue());
                  qbMember.setFace(face);
                  qbMember.setBirthday(birthday_date);
                  qbMember.setSex(sex);
                  qbMember.setNickname(nickname);
                  QbMember member = qbMemberMapper.selectById(requestDto.getAppUserId());
                  int result = 0;
                  if (member==null){
                      result = qbMemberMapper.insert(qbMember);
                  }else {
                      result = qbMemberMapper.updateById(qbMember);
                  }
                  if (ValidateUtils.isGreaterThan0(result)){
                      resultDto.setMsg("修改成功");
                  }else {
                      resultDto.setMsg(ErrorCode.E11003);
                      resultDto.setCode(ErrorCode.C11003);
                  }
              }
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto myAccount(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            QbMember qbMember = qbMemberMapper.selectById(searchDto.getAppUserId());
            Map map = new HashedMap();
            map.put("account",qbMember.getAccount());
            resultDto.setData(map);
            resultDto.setMsg("查询成功");
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto myRidingDetail(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            //连表查询 不连表会导致数据不一致性
            List<QbRidingDetailDto> ridingDetailDtos = qbRidingDetailMapper.selectMyRidingDetail(searchDto);
            ridingDetailDtos.forEach((riding)->{
                String time_str = DateUtil.timeStamp2Date(riding.getPay_time(),DateUtils.PATTERN_DATE+" HH:mm:ss");
                riding.setRiding_time_str(time_str);
            });
            if (ridingDetailDtos.size()==0){
                resultDto.setCode(ErrorCode.C11001);
                resultDto.setMsg(ErrorCode.E11001);
                return resultDto;
            }
            resultDto.setData(ridingDetailDtos);
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto myInvoiceRiding(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            //连表查询 不连表会导致数据不一致性
            List<QbRidingDetailDto> ridingDetailDtos = qbRidingDetailMapper.selectMyInvoiceRiding(searchDto);
            ridingDetailDtos.forEach((riding)->{
                String time_str = DateUtil.timeStamp2Date(riding.getRiding_time(),DateUtils.PATTERN_DATE+" HH:mm:ss");
                riding.setRiding_time_str(time_str);
            });
            if (ridingDetailDtos.size()==0){
                resultDto.setCode(ErrorCode.C11001);
                resultDto.setMsg(ErrorCode.E11001);
                return resultDto;
            }
            resultDto.setData(ridingDetailDtos);
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto writeInvoiceInfo(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            int header_type = filed.getInt("header_type");
            String header_name = filed.getString("header_name");
            String invoice_content = filed.getString("invoice_content");
            String remarks = filed.getString("remarks");
            Double invoice_money = filed.getDouble("invoice_money");
            String addressee_name = filed.getString("addressee_name");
            String addressee_phone = filed.getString("addressee_phone");
            int province = filed.getInt("province");
            int city = filed.getInt("province");
            int county = filed.getInt("county");
            String detailed_address = filed.getString("detailed_address");
            //保存信息
            QbInvoice qbInvoice = new QbInvoice();
            qbInvoice.setUid(searchDto.getAppUserId().intValue());
            qbInvoice.setAdd_time(searchDto.getTime().intValue());
            qbInvoice.setAddressee_name(addressee_name);
            qbInvoice.setAddressee_phone(addressee_phone);
            qbInvoice.setCity(city);
            qbInvoice.setCounty(county);
            qbInvoice.setProvince(province);
            qbInvoice.setInvoice_money(invoice_money);
            qbInvoice.setRemarks(remarks);
            qbInvoice.setInvoice_content(invoice_content);
            qbInvoice.setDetailed_address(detailed_address);
            qbInvoice.setHeader_name(header_name);
            qbInvoice.setHeader_type(header_type);
            qbInvoice.setInvoice_status(1);
            qbInvoiceMapper.insert(qbInvoice);
            resultDto.setMsg("申请成功");
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto myInvoiceInfo(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            EntityWrapper entityWrapper = new EntityWrapper();
            entityWrapper.where(" uid={0} ",searchDto.getAppUserId()).orderBy("add_time",false);
            RowBounds rowBounds = new RowBounds(searchDto.getPageNo(),searchDto.getPageSize());
            List<QbInvoice> invoices = qbInvoiceMapper.selectPage(rowBounds,entityWrapper);
            if (invoices.size()==0){
                resultDto.setCode(ErrorCode.C11001);
                resultDto.setMsg(ErrorCode.E11001);
                return resultDto;
            }else {
                JSONArray invoiceArr = new JSONArray();
                invoices.forEach((invoice)->{
                    JSONObject invoice_json = new JSONObject();
                    String time_str = DateUtil.timeStamp2Date(invoice.getAdd_time(),DateUtil.PATTERN_DATE_TIME_DD);
                    invoice_json.put("add_time",time_str);
                    invoice_json.put("invoice_status",invoice.getInvoice_status());
                    invoice_json.put("invoice_money",invoice.getInvoice_money());
                    invoiceArr.add(invoice_json);
                });
                resultDto.setData(invoiceArr);
            }
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto myCoupons(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            List<QbCouponAmountDto> coupons = qbCouponMapper.selectMyCoupons(searchDto);
            JSONArray couponArr = JSONArray.fromObject(coupons);
            couponArr.forEach((coupon)->{
                ((JSONObject)coupon).put("validity_end",DateUtil.
                        timeStamp2Date(((JSONObject) coupon).getLong("validity_end"),DateUtils.PATTERN_DATE));
            });
            resultDto.setData(couponArr);
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto aboutUs(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            List<QbAboutMe> aboutMes =  qbAboutMeMapper.selectList(new EntityWrapper<QbAboutMe>());
            if (aboutMes.size()==0){
                resultDto.setCode(ErrorCode.C11001);
                resultDto.setMsg(ErrorCode.E11001);
                return resultDto;
            }else {
                resultDto.setData(aboutMes.get(0));
            }
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto feedBack(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
             if (!filed.has("feedback_content")){
                  resultDto.setMsg(ErrorCode.E10011);
                  resultDto.setCode(ErrorCode.C10011);
                  return resultDto;
              }
            String feedback_content = filed.getString("feedback_content");
            QbFeedback qbFeedback = new QbFeedback();
            qbFeedback.setFeedback_content(feedback_content);
            qbFeedback.setFeedback_time(searchDto.getTime().intValue());
            qbFeedback.setUid(searchDto.getAppUserId().intValue());
            qbFeedbackMapper.insert(qbFeedback);
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            logger.info("意见反馈失败");
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto customerPhone(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            List<QbKefuTel> kefuTels = qbKefuTelMapper.selectList(new EntityWrapper<QbKefuTel>());
            if (kefuTels.size()==0){
                resultDto.setCode(ErrorCode.C11001);
                resultDto.setMsg(ErrorCode.E11001);
                return resultDto;
            }else {
                resultDto.setData(kefuTels.get(0));
            }
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto limitPay(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            //先查我的账户余额
            QbMember qbMember = new QbMember();
            qbMember.setUid(searchDto.getAppUserId().intValue());
            qbMember = qbMemberMapper.selectOne(qbMember);
            EntityWrapper entityWrapper = new EntityWrapper();
            List<QbLimitMoney> qbLimitMoneys = qbLimitMoneyMapper.selectList(entityWrapper);
            if (qbLimitMoneys.size()==0){
                resultDto.setCode(ErrorCode.C11001);
                resultDto.setMsg(ErrorCode.E11001);
                return resultDto;
            }
            QbLimitMoney qbLimitMoney = qbLimitMoneys.get(0);
            double mustMoney = qbLimitMoney.getMust_money()-qbMember.getAccount();
            qbLimitMoney.setMust_money(mustMoney);
            resultDto.setData(qbLimitMoney);
            resultDto.setMsg("查询成功");
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    @Override
    public ResultDto myMoneyDetail(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            //先查我的充值退款明细
            //再查我的骑行明细
            //再将两者进行排序
            List<QbMoneyDetail> moneyDetails = qbMoneyDetailMapper.selectList(new EntityWrapper<QbMoneyDetail>().
                    where(" uid={0}",searchDto.getAppUserId()));
            List<QbRidingDetail> ridingDetails = qbRidingDetailMapper.selectList(new EntityWrapper<QbRidingDetail>().
                    where(" uid={0} and riding_type=2 ",searchDto.getAppUserId()));
            if (moneyDetails.size()==0 && ridingDetails.size()==0){
                resultDto.setMsg(ErrorCode.E11001);
                resultDto.setCode(ErrorCode.C11001);
                return resultDto;
            }else if (moneyDetails.size()!=0 && ridingDetails.size()==0){
                //将moneyDetail的字段转换成返回的字段名称
                JSONArray moneyArr = JSONArray.fromObject(moneyDetails);
                JSONArray moneyResultArr = new JSONArray();
                moneyArr.forEach((money)->{
                    JSONObject result = new JSONObject();
                    result.put("pay_money",((JSONObject) money).remove("flow_money"));
                    result.put("type",((JSONObject) money).remove("type"));
                    String date = DateUtil.timeStamp2Date(((JSONObject) money).getLong("flow_time"),"MM-dd HH:mm");
                    result.put("pay_time",date);
                    moneyResultArr.add(result);
                });
                resultDto.setData(moneyResultArr);
            }else if (moneyDetails.size()==0 && ridingDetails.size()!=0){
                JSONArray ridingArr = JSONArray.fromObject(ridingDetails);
                JSONArray ridingResultArr = new JSONArray();
                ridingArr.forEach((riding)->{
                    JSONObject ridingResult = new JSONObject();
                    ridingResult.put("pay_money",((JSONObject)riding).remove("pay_money"));
                    ridingResult.put("type",3);
                    ridingResult.put("riding_time",((JSONObject) riding).remove("riding_time"));
                    String date = DateUtil.timeStamp2Date(((JSONObject) riding).getLong("pay_time"),"MM-dd HH:mm");
                    ridingResult.put("pay_time",date);
                    ridingResultArr.add(ridingResult);
                    resultDto.setData(ridingResultArr);
                });
            }else if (moneyDetails.size()!=0 && ridingDetails.size()!=0){
                JSONArray ridingArr = JSONArray.fromObject(ridingDetails);
                JSONArray moneyArr = JSONArray.fromObject(moneyDetails);
                JSONArray ridingResultArr = new JSONArray();

                ridingArr.forEach((ride)->{
                    ((JSONObject)ride).put("type",3);
                });

                moneyArr.forEach((money)->{
                    JSONObject result = new JSONObject();
                    result.put("pay_money",((JSONObject) money).remove("flow_money"));
                    result.put("pay_time",((JSONObject) money).remove("flow_time"));
                    result.put("type",((JSONObject) money).remove("type"));
                    ridingArr.add(result);
                });
                //进行排序
                List<QbRidingDetailDto> ridingDetailList = JSONArray.toList(ridingArr,QbRidingDetailDto.class);
                Collections.sort(ridingDetailList,Comparator.comparing(QbRidingDetailDto::getPay_time).reversed());
                JSONArray ridingArrs = JSONArray.fromObject(ridingDetailList);
                ridingArrs.forEach((riding)->{
                    JSONObject ridingResult = new JSONObject();
                    ridingResult.put("pay_money",((JSONObject)riding).remove("pay_money"));
                    ridingResult.put("type",((JSONObject) riding).remove("type"));
                    ridingResult.put("riding_time",((JSONObject) riding).remove("riding_time"));
                    String date = DateUtil.timeStamp2Date(((JSONObject) riding).getLong("pay_time"),"MM-dd HH:mm");
                    ridingResult.put("pay_time",date);
                    ridingResultArr.add(ridingResult);
                });

                resultDto.setData(ridingResultArr);
            }
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

    public ResultDto checkSMS(SearchDto searchDto) {
        ReentrantLock lock = new ReentrantLock();
        lock.lock();
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        try{
            if (!filed.has("phone") || !filed.has("validateCode")){
                resultDto.setMsg(ErrorCode.E10011);
                resultDto.setCode(ErrorCode.C10011);
                return resultDto;
            }
            long phone = filed.getLong("phone");
            int validateCode = filed.getInt("validateCode");
            if(!ValidateUtils.isMobileNO(phone)){
                resultDto.setCode(ErrorCode.C10004);
                resultDto.setMsg(ErrorCode.E10004);
                return  resultDto;
            }
            EntityWrapper entityWrapper = new EntityWrapper();
            //登录这里sendType=1是写死的
            entityWrapper.where(" mobile = {0} sendType=1" , phone
            );
            entityWrapper.orderBy("validity",false);
            List<QbSms> messageList = qbSmsMapper.selectList(entityWrapper);
            if(messageList.isEmpty()){
                resultDto.setCode(ErrorCode.C10006  );
                resultDto.setMsg(ErrorCode.E10006);
                return  resultDto;
            }

            QbSms sms =  messageList.get(0);
            if( Integer.parseInt(sms.getCheckcode()) != validateCode){
                resultDto.setCode(ErrorCode.C10006  );
                resultDto.setMsg(ErrorCode.E10006);
                return  resultDto;
            }
            if( DateUtils.getTimeSecondLong() > sms.getValidity() ){
                resultDto.setCode(ErrorCode.C10007);
                resultDto.setMsg(ErrorCode.E10007);
                return  resultDto;
            }
            resultDto.setMsg("校验通过");
        }finally {
            lock.unlock();
        }
        return resultDto;
    }

    public static void main(String args[]) {
//        String time = DateUtils.getNowDateTime("yyyy.MM.dd");
//        int times = DateUtils.getStringToInt_seconds("2017.07.10","yyyy.MM.dd");
        String time2 = DateUtil.timeStamp2Date(1499911096,"yyyy.MM.dd HH:mm:ss");
        System.out.println(1499911096);
        System.out.println(time2);
    }
}

